<?php
    class sfEmail{
        private $from;
        private $to;
        private $subject;
        private $body;
 
        public function __construct($from = NULL, $to, $subject, $body, $type = "text/plain"){
            $this->from = $from;
            $this->to = $to;
            $this->subject = $subject;
            $this->body = $body;
            $this->type = $type;
        }
        public function send(){
            $email = sfContext::getInstance()->
                    getMailer()->
                    compose(array($this->from[0] => $this->from[1]),
                            $this->to,
                            $this->subject,
                            $this->body)->setContentType($this->type);
            sfContext::getInstance()->
                    getMailer()->
                    send($email);

        }
    }
    class sfEmailManager{
        private $from;
        public function __construct(){
            $this->from[0] = sfConfig::get("app_email_from");
            $this->from[1] = sfConfig::get("app_email_name");
        }
        public function getFrom(){
            return $this->from;
        }
        public function createEmail($to, 
                                    $subject,
                                    $body, $useTemplate = true){
            $type = "text/plain";
            if($useTemplate){
                sfContext::getInstance()->getConfiguration()->loadHelpers(array('Partial')) ;
                $body = get_partial('sfEmail/pattern', array("subject" => $subject, "message" => $body));
                $type = "text/html";
            }
            $email = new sfEmail($this->getFrom(), $to, $subject, $body, $type);

            return $email;
        }
        public static function getSingleton()
        {
            if (!isset(self::$instance)) {
                $c = __CLASS__;
                self::$instance = new $c;
            }

            return self::$instance;
        }
        private static $instance;
    }
?>
